<template>
  <div>

    <div v-for="(group, orderNumber) in groupedProducts" :key="orderNumber">
      {{ group }}
      <h2>订单号 {{ orderNumber }}</h2>
      <ul>
        <li v-for="product in group" :key="product.id">{{ product.goodsName }}</li>
      </ul>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data() {
    return {
      products: [

      ],
    };
  },
  created() {
    axios.post('http://localhost:8080/goods//searchOrderItem/1').then(resp => {
      this.products = resp.data
      console.log(resp.data);
    })
  },
  computed: {
    groupedProducts() {
      const groups = {};
      this.products.forEach(product => {
        if (!groups[product.orderId]) {
          groups[product.orderId] = [];
        }
        groups[product.orderId].push(product);
      });
      return groups;
    },
  },
};
</script>
